package java8.myStream;

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * 功能描述:汇总统计 max,min,count,avg,sum 一次性汇总
 * 2024/08/26
 *
 * @author ZhangYi
 */
public class AggregateStatistical {

	public static void main(String[] args) {
		List<Person> people = Arrays.asList(
				new Person("Alice", 20),
				new Person("Bob", 17),
				new Person("Charlie", 22),
				new Person("Diana", 19),
				new Person("Eve", 25),
				new Person("Frank", 16)
		);

		// 使用 summarizingInt 方法按年龄统计
		IntSummaryStatistics ageStats = people.stream()
				.collect(Collectors.summarizingInt(Person::getAge));

		System.out.println(ageStats.getAverage());
		System.out.println(ageStats.getMax());
		System.out.println(ageStats.getMin());
		System.out.println(ageStats.getSum());
		System.out.println(ageStats.getCount());
		System.out.println("Age Summary Statistics: " + ageStats);
	}
}
